import java.util.LinkedList;
import java.util.Queue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-11-15
 * Time:17:24
 */
public class MyStack {
        Queue<Integer> quene1;
        Queue<Integer> quene2;
        public MyStack() {
            quene1=new LinkedList<>();
            quene2=new LinkedList<>();
        }

        public void push(int x) {
            if(quene1.isEmpty()&&quene2.isEmpty()){
                quene1.offer(x);
            }else if(quene1.isEmpty()){
                quene2.offer(x);
            }else{
                quene1.offer(x);
            }
        }

        public int pop() {
            if(quene1.isEmpty()&&quene2.isEmpty()){
                return -1;
            }else if(quene1.isEmpty()){
                int size=quene2.size();
                for(int i=0;i<size-1;i++){
                    quene1.offer(quene2.poll());
                }
                return quene2.poll();
            }else{
                int size=quene1.size();
                for(int i=0;i<size-1;i++){
                    quene2.offer(quene1.poll());
                }
                return quene1.poll();
            }
        }

        public int top() {
            if(quene1.isEmpty()&&quene2.isEmpty()){
                return -1;
            }else if(quene1.isEmpty()){
                int size=quene2.size();
                for(int i=0;i<size-1;i++){
                    quene1.offer(quene2.poll());
                }
                int x=quene2.peek();
                quene1.offer(quene2.poll());
                return x;
            }else{
                int size=quene1.size();
                for(int i=0;i<size-1;i++){
                    quene2.offer(quene1.poll());
                }
                int x=quene1.peek();
                quene2.offer(quene1.poll());
                return x;
            }
        }

        public boolean empty() {
            if(quene1.isEmpty()&&quene2.isEmpty()){
                return true;
            }
            return false;
        }

}
